﻿/*
*	左侧按钮点击事件
*/

$(document).ready(function () {
    umcl_fixedleft(); //固定左侧
    umcl_click_contact(); //联系人
    umcl_click_task(); //任务
    umcl_click_product(); //产品
    umcl_click_trade(); //交易
    umcl_click_usercenter(); //个人中心
    umcl_click_logoff();
});

//数据
var isfixedleft = false; //是否固定左侧

var firstcontact = true; //第一次载入联系人
var firstproduct = true; //第一次载入产品
var firsttrade = true; //第一次载入交易
var firstusercenter = true; //第一次载入用户中心


//固定左侧
function umcl_fixedleft() {
    $("#left_mosttop_ul_a").click(function (event) {
        if (!isfixedleft) { //没有固定
            $("#left_mosttop_ul_a").css("background-position", "0px -625px");
            isfixedleft = true;
        } else { //已经固定
            $("#left_mosttop_ul_a").css("background-position", "0px -600px");
            isfixedleft = false;
        }
    });
    $("#left_mosttop_ul_a")
    .mouseover(function () {
        if (!isfixedleft) { //没有固定
            $("#left_mosttop_ul_a").css("background-position", "0px -625px");
        } else { //已经固定
            $("#left_mosttop_ul_a").css("background-position", "0px -600px");
        }
    })
    .mouseout(function () {
        if (!isfixedleft) { //没有固定
            $("#left_mosttop_ul_a").css("background-position", "0px -600px");
        } else { //已经固定
            $("#left_mosttop_ul_a").css("background-position", "0px -625px");
        }
    });
}

//任务
function umcl_click_task() {
    $("#left_third_ul_a").click(function (event) {

        $('#right_task_div').show();

        $('#right_contact_div').css("opacity", "0");
        $('#right_product_div').css("opacity", "0");
        $('#right_trade_div').css("opacity", "0");
        $('#right_usercenter_div').css("opacity", "0");
        $('#right_task_div').css("opacity", "1");

        $('#right_contact_div').hide();
        $('#right_product_div').hide();
        $('#right_trade_div').hide();
        $('#right_usercenter_div').hide();
    });
}

///联系人
function umcl_click_contact() {
    $("#left_second_ul_a").click(function (event) {

        if (firstcontact) { //第一次载入联系人页
            firstcontact = false;
            //          loadjscssfile("../../Scripts/JQ/UserMain/UM_Contact.js", "js");
            //          loadjscssfile("../../Scripts/JQ/UserMain/UM_Contact_Click.js", "js");
            //          loadjscssfile("../../Content/css/user_contact.css", "css");
            var d = new Date()
            var vYear = d.getFullYear();
            var vMon = d.getMonth() + 1;
            var vDay = d.getDate();
            var date = vYear + "-" + vMon + "-" + vDay;

            //第一个添加新联系人的div
            var new_contact_div = $("<div id='contact_box_div_id' class='contact_box_div'>"
                         + "<!-- 联系人相片 -->"
                         + "<div class='contact_photo_div'>"
                         + "    <img src='../../Content/image/system/contact/undefine.png'>"
                         + "</div>"
                         + "<!-- /联系人相片 -->   "
                         + "<!-- 联系人标签 -->"
                         + " <div class='contact_tag_div'>"
                         + "      <li>#标签</li>"
                         + " </div>"
                         + " <!-- 联系人信息 -->"
                         + " <div class='contact_info_div'>"
                         + "      <ul>"
                         + "      <li class='contact_info_div_p_li_name'><input type='text'  name='username' id='contact_name_input_id' class='contact_name_input'  maxlength='50' placeholder='联系人姓名' /> </li>"
                         + "     </ul>"
                         + "      <ul class='contact_info_div_ul'>"
                         + "      <li class='contact_info_div_p_li'>tel:</li>"
                         + "      <li class='contact_info_div_p_li_input'><input type='text'  name='username' id='contact_phone_input_id' class='contact_phone_input'  maxlength='50' placeholder='联系人电话' /> </li>"
                         + "      </ul>"
                         + "  </div>"
                         + " <!-- 联系人添加时间 -->"
                         + " <div class='contact_addtime_div'>"
                         + "  <p class='contact_addtime_div_line'> </p>"
                         + "       <p> // " + date + "<a class='contact_add_a'></a></p>"
                         + " </div>"
                         + " </div>");
            $("#right_contact_div").append(new_contact_div);

            var reg = new RegExp("(^|&)" + "name" + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象

            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            var email = null;
            if (r != null)
                email = unescape(r[2]);

            $.ajax({
                url: "/Mange_Main/GetContact",
                type: "post",
                cache: false,
                data: {
                    email: email
                },
                dataType: "json",
                success: function (msg) {
                    if (msg.Result) {
                        //动态添加的存在的联系人的div
                        for (var i = 0; i < msg.count; i++) {
                            var contact_set = {}; //联系人集合
                            contact_set[i] = $("<div class='contact_box_div'>"
                                             + "<!-- 联系人相片 -->"
                                             + "<div class='contact_photo_div'>"
                                             + "    <img src='" + msg.contact_image[i] + "'>"
                                             + "</div>"
                                             + "<!-- /联系人相片 -->   "
                                             + "<!-- 联系人标签 -->"
                                             + " <div class='contact_tag_div'>"
                                             + "      <li>#标签</li>"
                                             + " </div>"
                                             + " <!-- 联系人信息 -->"
                                             + " <div class='contact_info_div'>"
                                             + "      <ul>"
                                             + "      <li class='contact_info_div_p_li_name'><input type='text'  class='contact_name_input'  maxlength='50' placeholder='联系人' value='" + msg.contact_name[i] + "' /> </li>"
                                             + "     </ul>"
                                             + "      <ul class='contact_info_div_ul'>"
                                             + "      <li class='contact_info_div_p_li'>tel:</li>"
                                             + "      <li class='contact_info_div_p_li_input'><input type='text'  class='contact_phone_input'  maxlength='50' placeholder='电话' value='" + msg.contact_phone[i] + "' /> </li>"
                                             + "      </ul>"
                                             + "  </div>"
                                             + " <!-- 联系人添加时间 -->"
                                             + " <div class='contact_addtime_div'>"
                                             + "  <p class='contact_addtime_div_line'> </p>"
                                             + "       <p> // " + msg.contact_time[i] + " <input class='hide_contactid_input' type='hidden'; value='" + msg.contact_id[i] + "'/>"
                                             + "       <span class='contact_manage_span' ><a class='contact_alter_a'></a><a class='contact_delete_a'></a><a class='contact_avatar_a'></a><a class='contact_recover_a'></a><span>"
                                             + "       </p>"
                                             + " </div>"
                                             + " </div>");
                            $("#right_contact_div").append(contact_set[i]);

                        }
                        umc_waterfallset(); //瀑布流一下
                    } else {
                        alert("加载错误");
                    }
                }
            });
        }
        //$("#right_contact_div").css("width", "110%");

        umc_waterfallset(); //瀑布流一下

        $('#right_contact_div').show();

        $('#right_task_div').css("opacity", "0");
        $('#right_product_div').css("opacity", "0");
        $('#right_trade_div').css("opacity", "0");
        $('#right_usercenter_div').css("opacity", "0");
        $('#right_contact_div').css("opacity", "1");

        $('#right_task_div').hide();
        $('#right_product_div').hide();
        $('#right_trade_div').hide();
        $('#right_usercenter_div').hide();
    });
}

//产品
function umcl_click_product() {
    $("#left_four_ul_a").click(function (event) {

        if (firstproduct) {
            firstproduct = false;
            //添加产品的div
            var add_product_div = $("<!-- 添加产品的div -->"
            //                + "<div id='add_rp_productdiv_id' ><div class='add_product' ><a id='product_openadddiv_a'></a></div>"
                + "<div class='rp_productitem' id='add_rp_productitem_id' '>"
                + "    <!-- 产品图片 -->"
                + "    <div class='rp_productitem_photo_div' >"
                + "        <img class='rp_productitem_photo_img' src='../../Content/image/system/product/1undefineproduct.jpg'>"
                + "  </div>"
                + "  <!-- /产品图片 -->"
                + "  <!-- 产品信息 -->"
                + "  <div class='rp_productitem_info_div'>"
                + "      <ul class='rp_productitem_info_div_detailinfo'>"
                + "          <li class='rp_productitem_info_div_detailinfo_li'>名称：<input type='text' name='username' class='rp_name' maxlength='50' placeholder='填写名称' />"
                + "          </li>"
                + "          <li class='rp_productitem_info_div_detailinfo_li'>库存：<input type='text' name='username' class='rp_sum' maxlength='50' placeholder='填写库存' />"
                + "          </li>"
                + "          <li class='rp_productitem_info_div_detailinfo_li'>单价：<input type='text' name='username' class='rp_price' maxlength='50' placeholder='填写单价' />"
                + "          </li>"
                + "      </ul>"
                + "      <ul>"
                + "          <table class='rp_productitem_info_div_decript_table' cellpadding='0' cellspacing='0'  border='0'>"
                + "              <tr>"
                + "                  <td class='rp_productitem_info_div_decript_table_label'>"
                + "                      <label>"
                + "                          描述：</label><span class='product_manage_span' ><a class='product_add_a'></a><span>"
                + "                  </td>"
                + "                  <!-- -->"
                + "                  <td class='rp_productitem_info_div_decript_table_input'>"
                + "                      <textarea cols='50' rows='10' class='rp_descript' maxlength='1024' placeholder='填写描述'></textarea>"
                + "                  </td>"
                + "              </tr>"
                + "          </table>"
                + "      </ul>"
                + "  </div>"
                + "  <!-- /产品信息 -->"
                + "</div></div>"
                + "<!-- /添加产品的div -->");
            $("#rp_function_div").append(add_product_div);

            var add_product_div2 = $("<div id='rp_productlist_div'></div>");
            $("#rp_function_div").append(add_product_div2);
            //            $("#add_rp_productitem_id").hide();
            //            $("#add_product_mosttop_a").hide();


            var email = $("#ru_g_id").val();
            email = $.trim(email);

            //初始化已有产品
            $.ajax({
                url: "/Mange_Main/GetAllContact",
                type: "post",
                cache: false,
                data: {
                    email: email
                },
                dataType: "json",
                success: function (msg) {
                    if (msg.Result) {
                        for (var i = 0; i < msg.count; i++) {
                            var product_set = {}; //联系人集合
                            product_set[i] = $("<!-- 添加产品的div -->"
                                        + "<div class='rp_productitem' style='margin-top:10px;'>"
                                        + "    <!-- 产品图片 -->"
                                        + "    <div class='rp_productitem_photo_div' >"
                                        + "        <img class='rp_productitem_photo_img' src='../../Content/image/system/product/undefineproduct.jpg'>"
                                        + "  </div>"
                                        + "  <!-- /产品图片 -->"
                                        + "  <!-- 产品信息 -->"
                                        + "  <div class='rp_productitem_info_div'>"
                                        + "      <ul class='rp_productitem_info_div_detailinfo'>"
                                        + "          <li class='rp_productitem_info_div_detailinfo_li'>名称：<input type='text' name='username' class='rp_name' maxlength='50' placeholder='填写名称' value='" + msg.product_name[i] + "' />"
                                        + "          </li>"
                                        + "          <li class='rp_productitem_info_div_detailinfo_li'>库存：<input type='text' name='username' class='rp_sum' maxlength='50' placeholder='填写库存' value='" + msg.product_sum[i] + "' />"
                                        + "          </li>"
                                        + "          <li class='rp_productitem_info_div_detailinfo_li'>单价：<input type='text' name='username' class='rp_price' maxlength='50' placeholder='填写单价' value='" + msg.product_price[i] + "' />"
                                        + "          </li>"
                                        + "      </ul>"
                                        + "      <ul>"
                                        + "          <table class='rp_productitem_info_div_decript_table' cellpadding='0' cellspacing='0'  border='0'>"
                                        + "              <tr>"
                                        + "                  <td class='rp_productitem_info_div_decript_table_label'>"
                                        + "                      <label>"
                                        + "                          描述：</label><span class='product_manage_span' ><a class='product_avatar_a'></a><a class='product_recover_a'></a><a class='product_alter_a' ></a><a class='product_delete_a' ></a><span>"
                                        + "                  </td>"
                                        + "                  <!-- -->"
                                        + "                  <td class='rp_productitem_info_div_decript_table_input'>"
                                        + "                      <textarea cols='50' rows='10' class='rp_descript' maxlength='1024' placeholder='填写描述'>" + msg.product_decript[i] + "</textarea>"
                                        + "                      <input class='hide_productid_input' type='hidden'; value='" + msg.product_id[i] + "'/>"
                                        + "                  </td>"
                                        + "              </tr>"
                                        + "          </table>"
                                        + "      </ul>"
                                        + "  </div>"
                                        + "  <!-- /产品信息 -->"
                                        + "</div></div>"
                                        + "<!-- /添加产品的div -->");
                            $("#rp_productlist_div").append(product_set[i]);
                            $(".product_manage_span").hide();
                        }
                    }
                    else {
                    }
                }
            });
        }

        $('#right_product_div').show();

        $('#right_contact_div').css("opacity", "0");
        $('#right_task_div').css("opacity", "0");
        $('#right_trade_div').css("opacity", "0");
        $('#right_usercenter_div').css("opacity", "0");
        $('#right_product_div').css("opacity", "1");

        $('#right_contact_div').hide();
        $('#right_task_div').hide();
        $('#right_trade_div').hide();
        $('#right_usercenter_div').hide();
    });
}

//交易
function umcl_click_trade() {
    $("#left_five_ul_a").click(function (event) {




        if (firsttrade) {
            firsttrade = false;

            var email = $("#ru_g_id").val();
            email = $.trim(email);

            //初始化已有产品
            $.ajax({
                url: "/Mange_Main/GetAllTrade",
                type: "post",
                cache: false,
                data: {
                    email: email
                },
                dataType: "json",
                success: function (msg) {
                    if (msg.Result) {
                  
                        for (var i = 0; i < msg.count; i++) {
                            var trade_set = {}; //联系人集合
                            trade_set[i] = $("<!-- 交易列表item div-->"
                                + "<div class='rtr_tradelistitembox_div' ><div class='rtr_tradelistitem_div' >"
                                + "    <ul>"
                                + "        <li class='rtr_row_tradeid'><input type='text' class='rt_tradeid' maxlength='50' placeholder='ID' value='" + msg.trade_id[i] + "' readonly='true' disable='true'/></li>"
                                + "        <li class='rtr_row_tradetime'>"
                                + "            <input type='text' class='rt_tradetime' maxlength='50' placeholder='时间' value='" + msg.trade_time[i] + "' /></li>"
                                + "        <!-- 产品名 -->"
                                + "        <li class='rtr_row_tradename'>"
                                + "            <input type='text' class='rt_productname' maxlength='50' placeholder='产品名' value='" + msg.trade_refrences_product_name[i] + "' />"
                                + "            <a class='rt_productname_select'></a></li>"
                                + "        <!-- /产品名 -->"
                                + "        <li class='rtr_row_tradesum'>"
                                + "            <input type='text' class='rt_tradesum' maxlength='50' placeholder='数量(/件)' value='" + msg.trade_sum[i] + "' /></li>"
                                + "        <li class='rtr_row_tradeprice'>"
                                + "            <input type='text' class='rt_tradeprice' maxlength='50' placeholder='单价(/元)' value='" + msg.trade_price[i] + "' /></li>"
                                + "        <li class='rtr_row_tradeaccount'>"
                                + "            <input type='text' class='rt_tradeamount' maxlength='50' placeholder='总额(/元)' value='" + msg.trade_amount[i] + "' /></li>"
                                + "        <li class='rtr_row_tradecustom'>"
                                + "            <input type='text' class='rt_tradecustom' maxlength='50' placeholder='客户' value='" + msg.trade_customer[i] + "' /></li>"
                                + "        <div class='rtr_row_tradedescript'>"
                                + "            <input type='text' class='rt_tradedescript' maxlength='50' placeholder='备注' value='" + msg.trade_decript[i] + "' /></div>"
                                + "    </ul>"
                                + "</div></div>"
                                + "<!-- /交易列表item div -->");
                            $(".rtr_tradelist_div").append(trade_set[i]);
                        }
                    }
                    else {
                    }
                }
            });
        }


        $('#right_trade_div').show();

        $('#right_contact_div').css("opacity", "0");
        $('#right_task_div').css("opacity", "0");
        $('#right_product_div').css("opacity", "0");
        $('#right_usercenter_div').css("opacity", "0");
        $('#right_trade_div').css("opacity", "1");

        $('#right_contact_div').hide();
        $('#right_task_div').hide();
        $('#right_product_div').hide();
        $('#right_usercenter_div').hide();
    });
}

//个人中心
function umcl_click_usercenter() {
    $("#left_six_ul_a").click(function (event) {
        $('#right_usercenter_div').show();

        $('#right_contact_div').css("opacity", "0");
        $('#right_task_div').css("opacity", "0");
        $('#right_product_div').css("opacity", "0");
        $('#right_trade_div').css("opacity", "0");
        $('#right_usercenter_div').css("opacity", "1");

        $('#right_contact_div').hide();
        $('#right_task_div').hide();
        $('#right_product_div').hide();
        $('#right_trade_div').hide();
    });
}


////注销
function umcl_click_logoff() {
    $("#left_seven_ul_a").click(function (event) {
        $.ajax({
            url: "/Mange_State/Log_Off",
            type: "post",
            cache: false,
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {
                    window.location.href = "/View_Login/Login";
                }
            }
        });
    });
}



/*
*	原始状态
$('#right_contact_div').css("opacity", "0");
$('#right_task_div').css("opacity", "0"); 
$('#right_product_div').css("opacity", "0"); 
$('#right_trade_div').css("opacity", "0"); 
$('#right_usercenter_div').css("opacity", "0"); 


隐藏
$('#right_contact_div').hide();
$('#right_task_div').hide();
$('#right_product_div').hide();
$('#right_trade_div').hide();
$('#right_usercenter_div').hide();

*/